Skip to content

Clean up native Codegen staging directories - #60058

Merged
meta-codesync[bot] merged 2 commits into
react:mainfrom
jipeng6036-del:fix/codegen-clean-up-temporary-artifacts
Nov 17, 2026
Merged

meta-codesync[bot] merged 2 commits into
react:mainfrom
jipeng6036-del:fix/codegen-clean-up-temporary-artifacts

Conversation

@jipeng6036-del

Copy link
Copy Markdown
Contributor

Summary:

Fixes #60057. The Codegen executor stages each library's generated files in a temporary directory and copies them to the configured output. Repeated invocations leave those staging directories behind. Remove the fresh staging directory in a finally block so it is cleaned up after both successful generation and a generator error.

Thanks to @YevheniiKotyrlo for the CLI reproducer and the build observations. I used Codex to help implement and verify the fix.

Changelog:

[GENERAL] [FIXED] - Clean up temporary native Codegen artifacts after generation.

Test Plan:

  • Both new regression tests failed on the base revision and passed with the change. They cover successful generation and a generator error.
  • Ran scripts/generate-codegen-artifacts.js for a minimal iOS module fixture on Windows. The three generated files were byte-for-byte identical before and after the fix, and the temporary directory went from one leftover entry to zero.
  • The broader Codegen Jest run on Windows passed 53 tests. The same two podspec snapshots fail on the base and on this branch because they expect POSIX path separators.
  • ESLint and Prettier passed for both changed files.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 16, 2026
@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D132532185.

@javache

javache commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Please update packages/react-native/scripts/codegen/__tests__/generate-native-code-test.js too - not sure why these aren't running on github ci.

@jipeng6036-del

Copy link
Copy Markdown
Contributor Author

Thanks, @javache. generate-native-code-test.js is included in this PR with two cases: cleanup after successful generation and cleanup when generation throws. I checked the current Test All logs and the file passed on both Node 24 and Node 22.13.0.

@javache

javache commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Sorry, I was relaying feedback from the internal test fixer.

codegen-utils is not available as built in the test environment, so please mock it or adjust the test

jest.mock('../codegen-utils', () => ({
  getCodegen: () => ({
    generate: ({outputDirectory}: {outputDirectory: string}) => {
      const {writeFileSync} = require('node:fs');
      const {join} = require('node:path');
      writeFileSync(join(outputDirectory, 'TestSpec.h'), 'generated code');
    },
  }),
}));

@jipeng6036-del

Copy link
Copy Markdown
Contributor Author

Thanks for clarifying, @javache. I pushed fd8f70d using your codegen-utils mock. The test still checks that the generated file is copied and the staging directory is removed. Both cases pass with the built Codegen module unavailable.

@meta-codesync
meta-codesync Bot merged commit 6a695d8 into react:main Nov 17, 2026
86 of 87 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @jipeng6036-del in 6a695d8

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen leaves one folder per library in $TMPDIR on every pod install and Xcode build: generateCode never removes its mkdtempSync folder

3 participants